package jmine.tec.persist.jms.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import jmine.tec.persist.jms.domain.JMSMonitoringMessage;
import bancosys.tec.persist.dao.BaseDAO;
import bancosys.tec.utils.date.Timestamp;

/**
 * DAO para consultas de mensagens de monitoramento JMS.
 * 
 * @author queiroz
 */
public class JMSMonitoringMessageDAO extends BaseDAO<JMSMonitoringMessage> {

    /**
     * @return As mensagens de monitoramento enviadas nas últimas 24 horas.
     */
    public List<JMSMonitoringMessage> findLatest() {
        Timestamp yesterday = new Timestamp().addDays(-1);
        Criteria c = this.createCriteria();
        c.add(Restrictions.ge("sendTimestamp", yesterday));
        c.addOrder(Order.asc("sendTimestamp"));
        return this.executeQuery(c);
    }

    /**
     * @return As mensagens de monitoramento enviadas antes das últimas 24 horas.
     */
    public List<JMSMonitoringMessage> findOld() {
        Timestamp yesterday = new Timestamp().addDays(-1);
        Criteria c = this.createCriteria();
        c.add(Restrictions.lt("sendTimestamp", yesterday));
        c.addOrder(Order.asc("sendTimestamp"));
        return this.executeQuery(c);
    }

}
